package com.manage.competition.service.impl;

import com.manage.competition.entity.EnrollCollection;
import com.manage.competition.mapper.EnrollCollectionMapper;
import com.manage.competition.repository.EnrollCollectionRepository;
import com.manage.competition.service.IEnrollCollectionService;
import com.manage.competition.util.CurrentUserUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Create with IDEA
 *
 * @Author: gitee.com/KamisamaXX
 * @Date: Create in 9:11 2019/4/8
 * @Description:
 */
@Service
public class EnrollCollectionServiceImpl implements IEnrollCollectionService {

    @Autowired
    private EnrollCollectionMapper enrollCollectionMapper;

    @Autowired
    private EnrollCollectionRepository enrollCollectionRepository;

    @Override
    public int insert(EnrollCollection enrollCollection) {
        enrollCollection.setCreateUser(CurrentUserUtil.getCurrentUser().getUsername());
        enrollCollection.setUpdateUser(CurrentUserUtil.getCurrentUser().getUsername());
        return enrollCollectionMapper.insert(enrollCollection);

    }

    @Override
    public int update(EnrollCollection enrollCollection) {
        enrollCollection.setUpdateUser(CurrentUserUtil.getCurrentUser().getUsername());
        return enrollCollectionMapper.updateByPrimaryKeySelective(enrollCollection);
    }

    @Override
    public EnrollCollection findById(long id) {
        return enrollCollectionRepository.findById(id).orElse(null);
    }

    @Override
    public List<EnrollCollection> findByUserId(long userId) {
        return enrollCollectionRepository.findByUserId(userId);
    }

    @Override
    public EnrollCollection findByUserIdAndCompetitionId(Long id,Long competitionId) {
        return enrollCollectionRepository.findByUserIdAndCompetitionId(id,competitionId);
    }

    @Override
    public List<EnrollCollection> findByCompetitionId(long competitionId) {
        return enrollCollectionRepository.findByCompetitionId(competitionId);
    }
}
